<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:mo="https://gitee.com/aun/Timo1"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<body>

<div class="layui-card">

    <div class="layui-card-header">
        <span class="layui-icon font-s10 color-desc margin-right-5"></span>基本资料管理
        <div class="pull-right">
<!--            <button data-table-id="NoticeTable" class="layui-btn layui-btn-primary  layui-btn-sm" data-modal="/system/user/form" data-height="720px" data-width="800px">-->
<!--                <i class=" layui-icon layui-icon-addition"></i>新建护工</button>-->
        </div>
    </div>

    <div class="layui-card-line"></div>

    <div class="layui-card-body">

        <div class="layui-card-table layui-tab">
            <div class="layui-tab-content">
                <form th:replace="/pcs/porter/index_search">

                </form>
                <table id="PorterTable" data-url="/pcs/porter/index" data-target-search="form.form-search"></table>
                <script type="text/javascript" th:inline="none">
                    $(function () {
                        $('#PorterTable').layTable({
                            even: true, height: 'full',where:{orderBy:"status:asc,id:desc"},
                            cols: [[
                                {title: '序号', type: 'numbers', width: 80},
                                {field: 'companyName', title: '陪护公司', align: 'center', minWidth: 250},
                                {field: 'name', title: '陪护员姓名', minWidth: 180, align: 'center'},
                                {field: 'sex', title: '性别', align: 'center', templet: function (d) {
                                    if (d.sex == 1) {
                                        return '男';
                                    } else if (d.sex == 2) {
                                        return '女';
                                    } else {
                                        return '未知';
                                    }
                                }},
                                {field: 'age', title: '年龄', align: 'center'},
                                {field: 'phone', title: '手机号', align: 'center', minWidth: 110},
                                {field: 'permission', title: '护理科室权限', align: 'center',templet: function (d) {
                                        var permission = d.porterPermissions;
                                        if (permission.length > 0) {
                                            var str = '';
                                            permission.forEach(function (item, index){
                                                if(item.verifyStatus==1){
                                                    str += '<span class="layui-badge layui-bg-green">'+item.depName+'</span>';
                                                }else{
                                                    str += '<span class="layui-badge layui-bg-gray">'+item.depName+'</span>';
                                                }
                                            })
                                            return str;
                                        } else {
                                            return '无';
                                        }
                                    }},
                                {field: 'status', title: '人员状态', align: 'center', templet: function (d) {
                                    if (d.status == 1) {
                                        return '<span style="color:#16b777;">在职</span>';
                                    } else if (d.status == 0) {
                                        return '<span style="color:#ff5722;">离职</span>';
                                    } else {
                                        return '未知';
                                    }
                                    }},
                                {field: 'expireSoonCount', title: '证书到期提醒', align: 'center', templet: function (d) {
                                        if (d.expireSoonCount == 0) {
                                            return '<span style="color:#16b777;">正常</span>';
                                        } else if (d.expireSoonCount > 0) {
                                            return '<a style="color:#ff5722;" data-modal="/pcs/porter/detail?id='+d.id+'">'+d.expireSoonCount+'个证书即将到期</a>';
                                        } else {
                                            return '未知';
                                        }
                                    }},

                                {field: 'contractEnd', title: '合同结束', align: 'center', minWidth: 110},
                                {toolbar: '#toolbar', title: '操作', align: 'center', minWidth: 250, fixed: 'right'}
                            ]]
                        });

                        layui.table.on('tool(PorterTable)', function(obj){
                            var that = this;
                            var data = obj.data;
                            let dropdown_data = [
                                {
                                    title: '编 辑',
                                    id: '1'
                                },
                                {
                                    title: '密 码',
                                    id: '2'
                                },
                                {
                                    title: '证书管理',
                                    id: '3'
                                },
                                {
                                    title: '人员续聘',
                                    id: '4'
                                },

                                {
                                    title: '删除',
                                    id: '6'
                                }
                            ];
                            if(data.status==1){
                                dropdown_data = [
                                    {
                                        title: '编 辑',
                                        id: '1'
                                    },
                                    {
                                        title: '密 码',
                                        id: '2'
                                    },
                                    // {
                                    //     title: '证书管理',
                                    //     id: '3'
                                    // },
                                    {
                                        title: '人员续聘',
                                        id: '4'
                                    },
                                    {
                                        title: '人员离职',
                                        id: '5'
                                    },
                                    {
                                        title: '删除',
                                        id: '6'
                                    },
                                ];
                            }

                            console.log("toolbar",data);
                            if(obj.event === 'more'){
                                // 更多下拉菜单
                                layui.dropdown.render({
                                    elem: that,
                                    show: true, // 外部事件触发即显示
                                    data: dropdown_data,
                                    click: function(data, othis){
                                        //根据 id 做出不同操作
                                        switch (data.id){
                                            case '1':
                                                $.form.modal("/pcs/porter/form?id="+obj.data.id,[],"编辑",[],"","","1000px")
                                                break;
                                            case '2':
                                                $.form.modal("/pcs/porter/pwd?id="+obj.data.id,[],"重置密码")
                                                break;
                                            case '3':
                                                $.form.modal("/pcs/porter/credentials/index?porterId="+obj.data.id,[],"证书管理")
                                                break;
                                            case '4':
                                                $.form.modal("/pcs/porter/hire?id="+obj.data.id,[],"人员续聘")
                                                break
                                            case '5':
                                                layer.confirm('<p style=\'text-align: center\'>您确定要将该陪护人员标记为离职状态吗？<br>此操作将更新该员工的状态为‘已离职’，并从在职人员列表中移除。<br>请确认此变更无误，因为一旦确认，相关在职信息及排班安排将自动调整。<br>是否继续执行离职状态变更？</p>', function(index){
                                                   $.form.load("/pcs/porter/state?id="+obj.data.id+"&status=0")
                                                    layer.close(index);
                                                });
                                                break
                                            case '6':
                                                layer.confirm('确定要删除吗?', function(index){
                                                    $.form.load("/pcs/porter/state?id="+obj.data.id+"&status=3")
                                                    obj.del();
                                                    layer.close(index);
                                                });
                                                break
                                        }



                                    },
                                    align: 'right', // 右对齐弹出
                                    style: 'box-shadow: 1px 1px 10px rgb(0 0 0 / 12%);' //设置额外样式
                                })
                            }
                        })




                    });





                </script>

                <!-- 数据状态切换模板 -->
                <script type="text/html" id="StatusSwitchTpl">
                    <input type="checkbox" value="{{d.id}}" lay-skin="switch" lay-text="已激活|已禁用" lay-filter="StatusSwitch" {{-d.status>0?'checked':''}}>
<!--                    {{-d.status ? '<b class="color-green">已启用</b>' : '<b class="color-red">已禁用</b>'}}-->
                </script>

                <script type="text/html" id="toolbar">
                    <a class="layui-btn layui-btn-sm" style="background-color: #16baaa" data-event-dbclick data-title="详情" shiro:hasPermission="pcs:porter:detail"    data-modal='/pcs/porter/detail?id={{d.id}}'>查看</a>
                    <a class="layui-btn layui-btn-sm" style="background-color: #16baaa" data-event-dbclick data-title="续聘记录" shiro:hasPermission="pcs:porter:hire:log"     data-modal='/pcs/porter/hire/log?id={{d.id}}'>续聘记录</a>

                    <a class="layui-btn layui-btn-sm"   shiro:hasPermission="pcs:porter:add" lay-event="more"  >更多<i class="layui-icon layui-icon-down"></i></a>


<!--                    <a class="layui-btn layui-btn-sm" data-event-dbclick data-title="编辑用户"  shiro:hasPermission="pcs:porter:add"  data-height="600px"  data-modal='/pcs/porter/form?id={{d.id}}'>编 辑</a>-->
<!--                    <a class="layui-btn layui-btn-sm layui-btn-normal" data-title="设置密码" data-height="420px" data-width="460px" data-modal='/pcs/porter/pwd?id={{d.id}}' shiro:hasPermission="pcs:porter:pwd">密 码</a>-->
<!--                    <a class="layui-btn layui-btn-sm" style="background-color: #16baaa" data-event-dbclick data-title="证书管理" shiro:hasPermission="pcs:porterCredentials:index"  data-height="600px"  data-modal='/pcs/porter/credentials/index?porterId={{d.id}}'>证书管理</a>-->
<!--                    <a class="layui-btn layui-btn-sm" style="background-color: #16baaa" data-event-dbclick data-title="人员续聘"  shiro:hasPermission="pcs:porter:hire"   data-modal='/pcs/porter/hire?id={{d.id}}'>人员续聘</a>-->

<!--                    {{# if(d.status==1){ }}-->
<!--                    <a class="layui-btn layui-btn-sm layui-btn-danger" data-event-dbclick  shiro:hasPermission="pcs:porter:state" data-confirm="<p style='text-align: center'>您确定要将该陪护人员标记为离职状态吗？<br>此操作将更新该员工的状态为‘已离职’，并从在职人员列表中移除。<br>请确认此变更无误，因为一旦确认，相关在职信息及排班安排将自动调整。<br>是否继续执行离职状态变更？</p>" data-action='/pcs/porter/state?id={{d.id}}&status=0'>人员离职</a>-->
<!--                    {{# } }}-->
<!--                    <a class="layui-btn layui-btn-sm layui-btn-danger" data-event-dbclick shiro:hasPermission="pcs:porter:state" data-confirm="确定要删除吗?" data-action='/pcs/porter/state?id={{d.id}}&status=3'>删除</a>-->
                </script>

            </div>
        </div>
    </div>

</div>
</body>
</html>